#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int N=2050;
const int INF=0x3f3f3f3f;
//dp[i][j]表示从前j个物品选出2*i个物品的最小疲劳
//所以dp[i][j]=min(dp[i][j-1],dp[i-1][j-2]+(a[j]-a[j-1])^2)
int dp[N][N];
int n,k;
int a[N];
int main(void){
    while(~scanf("%d%d",&n,&k)){
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
        }
        sort(a+1,a+n+1);
        memset(dp,INF,sizeof(dp));
        for(int i=0;i<=n;i++){
            dp[0][i]=0;
        }
        for(int i=1;i<=k;i++){
            for(int j=2;j<=n;j++){
                dp[i][j]=min(dp[i][j-1],dp[i-1][j-2]+(a[j]-a[j-1])*(a[j]-a[j-1]));
            }
        }
        printf("%d\n",dp[k][n]);
    }
    return 0;
}